package com.qf.service;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsGrouponMapper;
import com.qf.pojo.DtsGroupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.service
 * @Description:
 * @Date 2022/7/31 15:20
 */
@Service
public class GrouponServiceImpl implements  GrouponService {

    @Autowired
    private DtsGrouponMapper grouponMapper;


    @Override
    public IPage<DtsGroupon> queryByPage(Integer id, Integer page, Integer limit, String sort, String order) {

        //创建分页对象
        IPage<DtsGroupon> ipage = new Page<>(page, limit);

        //创建查询条件
        QueryWrapper<DtsGroupon> queryWrapper = new QueryWrapper<>();

        //判断查询条件是否为空
        if (id != null){
            queryWrapper.eq("id", id);
        }

        //排序
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order) ){
            if (order.equalsIgnoreCase("asc")){
                queryWrapper.orderByAsc(sort);
            }else {
                queryWrapper.orderByDesc(sort);
            }
        }
        //调用mapper
        IPage<DtsGroupon> iPage = grouponMapper.selectPage(ipage, queryWrapper);

        return iPage;
    }
}
